
\documentclass[a4paper]{article}

% SEE ALSO : unittest_colormap_input.tex

\usepackage{pgfplots}
    \usepgfplotslibrary{colorbrewer}
\usepackage{pgfplots.assert}
    \pgfplotsset{compat=1.14}

\begin{document}

%\tracingcommands=2\tracingmacros=2
%

\makeatletter

\pgfplotsset{
	colormap={initial}{rgb=(0,0,0) rgb=(1,0,0)},
	colormap={initial-5}{rgb=(0,0,0) rgb=(0,0.1,0) rgb=(0,0,0.2) rgb=(0.5,0,0) rgb=(1,0,1)},
}
{

\pgfplotscolormapserializetomacro{initial}\initial
\def\expected{%
	\expandafter \def \csname pgfpl@cm@initial@h\endcsname {1000.0}%
	\expandafter \def \csname pgfpl@cm@initial@invh\endcsname {0.001}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@initial}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@initial}%
		\fi
	}%
	\def \pgfpl@cm@initial@colspace {rgb}%
	\def \pgfpl@cm@initial@col@comps {3}%
	\def \pgfpl@cm@initial@lastindex {1}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@initial@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@initial@X}%
		\fi
	}%
	\def \pgfpl@cm@initial@X@scale@order@z {}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\initial}{unexpected initial}

\pgfkeys{/pgfplots/colormap access=map}%
\pgfplotscolormaptopdffunction{initial}
\def\actual{
	<< /FunctionType 3 /Domain [0 \pgfplotscolormappdfmax ]
	/Functions [ %
		<< /FunctionType 2 /Domain [0 1000] /C0 [0.0 0.0 0.0] /C1 [1.0 0.0 0.0] /N 1>> %
	]
	/Bounds []	/Encode [ 0 1] >>
}%
\pgfplotsassertequalstoknoexpand{\pgfplotsretval}{\actual}{unexpected actual}

\pgfkeys{/pgfplots/colormap access=piecewise constant}%
\pgfplotscolormaptopdffunction{initial}
\def\actual{
	<< /FunctionType 3 /Domain [0 \pgfplotscolormappdfmax ]
	/Functions [ %
		<< /FunctionType 2 /Domain [0 1000] /C1 [0.0 0.0 0.0] /C0 [1.0 0.0 0.0] /N 0>> %
		<< /FunctionType 2 /Domain [0 1000] /C1 [1.0 0.0 0.0] /C0 [1.0 0.0 0.0] /N 0>> %
	]
	/Bounds [ 500.0]	/Encode [ 0 1 0 1] >>
}%
\pgfplotsassertequalstoknoexpand{\pgfplotsretval}{\actual}{unexpected actual}

\pgfplotscolormapfind[0:1000]{500}{initial}
\pgfplotsassertequalstok{0.50354,0.0,0.0}{\pgfmathresult}{unexpected color}


\pgfkeys{/pgfplots/colormap access=map}%
\pgfplotscolormaptoshadingspec{initial}{1000pt}{\pgfplotsretval}
\def\actual{%
	rgb(0.0pt)=(0.0,0.0,0.0); rgb(1000.0pt)=(1.0,0.0,0.0)%
}%
\pgfplots@command@to@string\pgfplotsretval\pgfplotsretval
\pgfplots@command@to@string\actual\actual
\pgfplotsassertequalstoknoexpand{\pgfplotsretval}{\actual}{unexpected actual}
}

{
%\tracingcommands=2\tracingmacros=2
\pgfplotsset{
	colormap={actual}{
		color of colormap=(250 of initial)
		color of colormap={750 of initial}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {1000.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.001}%
	\def \pgfplots@loc@TMPa {{0.25177,0.0,0.0},{0.75531,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {1}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected actual}

\pgfplotscolormapfind[0:1000]{500}{actual}
\pgfplotsassertequalstok{0.50531,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfindpiecewiseconst[0:1000]{300}{actual}
% should be the first color:
\pgfplotsassertequalstok{0.25177,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfindpiecewiseconst[0:1000][1]{500}{actual}
% should be the second color as it receives its own interval:
\pgfplotsassertequalstok{0.75531,0.0,0.0}{\pgfmathresult}{unexpected color}
}

{
\pgfplotsset{
	colormap={actual}{
		color=(red)
		color of colormap(10pt)=(250 of initial)
		color of colormap(30pt)=(750 of initial)
	},
}
\pgfplotscolormapserializetomacro{actual}\ofcolormapwithpositions
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {333.32993}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.003}%
	\def \pgfplots@loc@TMPa {{1.0,0.0,0.0},{0.25177,0.0,0.0},{0.75531,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {2}%
	\def \pgfplots@loc@TMPa {0.0,333.32993,999.98978}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\ofcolormapwithpositions}{unexpected actual}

\pgfkeys{/pgfplots/colormap access=map}%
\pgfplotscolormaptopdffunction{actual}
\def\expected{
	<< /FunctionType 3 /Domain [0 \pgfplotscolormappdfmax ]
	/Functions [ %
		<< /FunctionType 2 /Domain [0 1000] /C0 [1.0 0.0 0.0] /C1 [0.25177 0.0 0.0] /N 1>> %
		<< /FunctionType 2 /Domain [0 1000] /C0 [0.25177 0.0 0.0] /C1 [0.75531 0.0 0.0] /N 1>> %
	]
	/Bounds [ 333.32993] /Encode [ 0 1 0 1] >>
}%
\pgfplotsassertequalstoknoexpand{\expected}{\pgfplotsretval}{unexpected actual}

\pgfkeys{/pgfplots/colormap access=piecewise constant}%
\pgfplotscolormaptopdffunction{actual}
\def\expected{
	 << /FunctionType 3 /Domain [0 \pgfplotscolormappdfmax ]
	 /Functions [
	 	<< /FunctionType 2 /Domain [0 1000] /C1 [1.0 0.0 0.0] /C0 [0.25177 0.0 0.0] /N 0>>
		<< /FunctionType 2 /Domain [0 1000] /C1 [0.25177 0.0 0.0] /C0 [0.75531 0.0 0.0] /N 0>>
		%<< /FunctionType 2 /Domain [0 1000] /C1 [0.75531 0.0 0.0] /C0 [0.75531 0.0 0.0] /N 0>>
	]
	/Bounds [ 333.32993] /Encode [ 0 1 0 1] >>
}%
\pgfplotsassertequalstoknoexpand{\expected}{\pgfplotsretval}{unexpected actual}

\pgfkeys{/pgfplots/colormap access=map}%
\pgfplotscolormaptoshadingspec{actual}{1000pt}{\pgfplotsretval}
\def\actual{%
	rgb(0.0pt)=(1.0,0.0,0.0); rgb(333.32993pt)=(0.25177,0.0,0.0); rgb(999.98978pt)=(0.75531,0.0,0.0)%
}%
\pgfplots@command@to@string\pgfplotsretval\pgfplotsretval
\pgfplots@command@to@string\actual\actual
\pgfplotsassertequalstoknoexpand{\actual}{\pgfplotsretval}{unexpected actual}

\pgfkeys{/pgfplots/colormap access=map}%
\pgfplotscolormaptoshadingspec{actual}{500pt}{\pgfplotsretval}
\def\actual{%
	rgb(0.0pt)=(1.0,0.0,0.0); rgb(166.66496pt)=(0.25177,0.0,0.0); rgb(499.99489pt)=(0.75531,0.0,0.0)%
}%
\pgfplots@command@to@string\pgfplotsretval\pgfplotsretval
\pgfplots@command@to@string\actual\actual
\pgfplotsassertequalstoknoexpand{\actual}{\pgfplotsretval}{unexpected actual}

\pgfplotscolormapfind[0:1000]{666.66666}{actual}
\pgfplotsassertequalstok{0.50352,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfind[0:1000]{1000}{actual}
\pgfplotsassertequalstok{0.75531,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfind[0:1000]{333.33328}{actual}
\pgfplotsassertequalstok{0.25177,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfindpiecewiseconst[0:1000]{249}{actual}
\pgfplotsassertequalstok{1.0,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfindpiecewiseconst[0:1000]{250}{actual}
\pgfplotsassertequalstok{1.0,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfindpiecewiseconst[0:1000]{0}{actual}
\pgfplotsassertequalstok{1.0,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfindpiecewiseconst[0:1000]{500}{actual}
\pgfplotsassertequalstok{0.25177,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfindpiecewiseconst[0:1000]{1000}{actual}
\pgfplotsassertequalstok{0.75531,0.0,0.0}{\pgfmathresult}{unexpected color}
}

{
\pgfplotsset{
	colormap={actual}{
		colors of colormap=({250,750} of initial)
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {1000.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.001}%
	\def \pgfplots@loc@TMPa {{0.25177,0.0,0.0},{0.75531,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {1}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}

% identical result:
\pgfplotsset{
	colormap={actual}{
		of colormap={colors={250,750}, source name=initial}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}

% another identical result:
\pgfplotsset{
	colormap name=initial,
	colormap={actual}{
		colors of colormap=(250,750)
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}

% another identical result:
\pgfplotsset{
	colormap={actual}{
		colors of colormap=(250,750 of initial)
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}
}

{
%\tracingcommands=2\tracingmacros=2
\pgfplotsset{
	colormap={actual}{
		samples of colormap=(4 of initial)
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {333.35243}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.003}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{0.33568,0.0,0.0},{0.67137,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {3}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}

% identical way:
\pgfplotsset{
	colormap={actual}{
		of colormap={samples=4, source name=initial}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}

% yet another identical way:
\pgfplotsset{
	colormap name=initial,
	colormap={actual}{
		samples of colormap={4}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}
}

{
\pgfplotsset{
	colormap={actual}{
		color=(red)
		colors of colormap(10pt)=({250,500,750} of initial)
	},
}
\pgfplotscolormapserializetomacro{actual}\ofcolormapwithpositions
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {333.32993}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.003}%
	\def \pgfplots@loc@TMPa {{1.0,0.0,0.0},{0.25177,0.0,0.0},{0.50354,0.0,0.0},{0.75531,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {3}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\ofcolormapwithpositions}{unexpected colors of colormap with pos}
}

{
\pgfplotsset{
	colormap={actual}{
		color=(red)
		color(10pt)=(red)
		colors of colormap(30pt)=({250,500,750} of initial)
	},
}
\pgfplotscolormapserializetomacro{actual}\ofcolormapwithpositions
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {200.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.005}%
	\def \pgfplots@loc@TMPa {{1.0,0.0,0.0},{1.0,0.0,0.0},{0.25177,0.0,0.0},{0.50354,0.0,0.0},{0.75531,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {4}%
	\def \pgfplots@loc@TMPa {0.0,200.0,600.0,800.0,1000.0}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\ofcolormapwithpositions}{unexpected colors of colormap with pos}

\pgfplotscolormapfind[0:1000]{600}{actual}
\pgfplotsassertequalstok{0.25177,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfind[0:1000]{200}{actual}
\pgfplotsassertequalstok{1.0,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfind[0:1000]{400}{actual}
\pgfplotsassertequalstok{0.62589,0.0,0.0}{\pgfmathresult}{unexpected color}
}

{
\pgfplotsset{
	colormap={actual}{
		color=(red)
		color(10pt)=(red)
		indices of colormap(30pt)=({1,0} of initial)
	},
}
\pgfplotscolormapserializetomacro{actual}\ofcolormapwithpositions
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {250.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.004}%
	\def \pgfplots@loc@TMPa {{1.0,0.0,0.0},{1.0,0.0,0.0},{1.0,0.0,0.0},{0.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {3}%
	\def \pgfplots@loc@TMPa {0.0,250.0,750.0,1000.0}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\ofcolormapwithpositions}{unexpected indices of colormap with pos}

\pgfplotscolormapfind[0:1000]{250}{actual}
\pgfplotsassertequalstok{1.0,0.0,0.0}{\pgfmathresult}{unexpected color}

\pgfplotscolormapfind[0:1000]{500}{actual}
\pgfplotsassertequalstok{1.0,0.0,0.0}{\pgfmathresult}{unexpected color}
}

{
\pgfplotsset{
	colormap={actual}{
		of colormap=(source pos={-100000,20000},source name=initial,colors,source range=-100000:20000)
	},
}
\pgfplotscolormapserializetomacro{actual}\ofcolormapwithpositions
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {1000.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.001}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {1}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\ofcolormapwithpositions}{unexpected actual}

% SAME but with curly braces:
\pgfplotsset{
	colormap={actual}{
		of colormap={source pos={-100000,20000},source name=initial,colors,source range=-100000:20000}
	},
}
\pgfplotscolormapserializetomacro{actual}\ofcolormapwithpositions
\pgfplotsassertequalstoknoexpand{\expected}{\ofcolormapwithpositions}{unexpected actual}
}

{
\pgfplotsset{
	colormap={actual}{
		of colormap={initial}
	},
}
\pgfplotscolormapserializetomacro{actual}\ofcolormapwithpositions
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {1000.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.001}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {1}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\ofcolormapwithpositions}{unexpected actual}
}

{
\pgfplotsset{
	colormap={actual}{
		of colormap={source pos={0,0}, initial}
	},
}
\pgfplotscolormapserializetomacro{actual}\ofcolormapwithpositions
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {1000.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.001}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{0.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {1}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\ofcolormapwithpositions}{unexpected actual}
}

{
\pgfplotsset{
	colormap={actual}{
		of colormap={colors={250,750,1000},source name=initial,target pos={0,100,1000}}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {100.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.01}%
	\def \pgfplots@loc@TMPa {{0.25177,0.0,0.0},{0.75531,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {2}%
	\def \pgfplots@loc@TMPa {0.0,100.0,1000.0}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}
}

{
% This is the SAME test case as above, but with a different
% formulation:
\pgfplotsset{
	colormap={actual}{
		colors of colormap={{250,750,1000} of initial,target pos={0,100,1000}}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {100.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.01}%
	\def \pgfplots@loc@TMPa {{0.25177,0.0,0.0},{0.75531,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {2}%
	\def \pgfplots@loc@TMPa {0.0,100.0,1000.0}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}
}

{
\pgfplotsset{
	colormap={actual}{
		samples of colormap={3 of initial,target pos={0,100,1000}}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {100.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.01}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{0.50354,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {2}%
	\def \pgfplots@loc@TMPa {0.0,100.0,1000.0}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}

% equivalent result:
\pgfplotsset{
	colormap name=initial,
	colormap={actual}{
		samples of colormap={3,target pos={0,100,1000}}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}
}

{
\pgfplotsset{
	colormap={actual}{
		samples of colormap={3 of initial,target pos={0,100,900,1000},sample for=const}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {100.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.01}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{0.50354,0.0,0.0},{1.0,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {3}%
	\def \pgfplots@loc@TMPa {0.0,100.0,900.0,1000.0}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}
}

{
\pgfplotsset{
	colormap={actual}{
		color=(green)
		samples of colormap={3 of initial,target pos={1000,2000,2500}}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {200.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.005}%
	\def \pgfplots@loc@TMPa {{0.0,1.0,0.0},{0.0,0.0,0.0},{0.50354,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {3}%
	\def \pgfplots@loc@TMPa {0.0,400.0,800.0,1000.0}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}
}

{
\pgfplotsset{
	colormap={actual}{
		of colormap={colors,source name=initial,target pos={0,100,1000}}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {100.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.01}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{0.50354,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {2}%
	\def \pgfplots@loc@TMPa {0.0,100.0,1000.0}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}
}

{
\pgfplotsset{
	colormap={actual}{
		of colormap={const colors,source name=initial-5,target pos={0,100,500,1000}}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {100.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.01}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{0.0,0.1,0.0},{0.5,0.0,0.0},{1.0,0.0,1.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {3}%
	\def \pgfplots@loc@TMPa {0.0,100.0,500.0,1000.0}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{unexpected colors of colormap}
}

{
\pgfplotsset{
	colormap={actual}{
		rgb(-1000)=(0,0,0) rgb(1000)=(1,0,0)
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {1000.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.001}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {1}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}
}

{
\pgfplotsset{
	colormap={actual}{
		rgb(-100)=(0,0,0) rgb(-50)=(0.5,0,0) rgb(100)=(1,0,0)
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {250.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.004}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,0.0},{0.5,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {2}%
	\def \pgfplots@loc@TMPa {0.0,250.0,1000.0}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}

% rescaling it -- should return same result
\pgfplotsset{
	colormap={actual}{
		rgb(-100000)=(0,0,0) rgb(-50000)=(0.5,0,0) rgb(100000)=(1,0,0)
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}
}

{
\pgfplotsset{
	colormap={actual}{
	% ensure that 'sample for=const' is only applied for the _last_
	% part of the definition:
		of colormap={
		  viridis,
		  target pos={0,200,400,600,800,1000},
		  sample for=const,
		},
		of colormap={
		  hot,
		  target pos={1200,1400,1600},
		  sample for=const,
		},
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {125.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.008}%
	\def \pgfplots@loc@TMPa {{0.267,0.00487,0.32942},{0.25317,0.26462,0.528},{0.1638,0.47098,0.55788},{0.13852,0.65842,0.51645},{0.47923,0.82039,0.31635},{0.99297,0.90611,0.14384},{0.0,0.0,1.0},{1.0,0.0,0.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {8}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}

% check the same, but with a different delimiter:
\pgfplotsset{
	colormap={actual}{
		of colormap={
		  viridis,
		  target pos={0,200,400,600,800,1000},
		  sample for=const,
		}
		of colormap={
		  hot,
		  target pos={1200,1400,1600},
		  sample for=const,
		}
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}

% check the same, but with a different delimiter:
\pgfplotsset{
	colormap={actual}{
		of colormap={
		  viridis,
		  target pos={0,200,400,600,800,1000},
		  sample for=const,
		};
		of colormap={
		  hot,
		  target pos={1200,1400,1600},
		  sample for=const,
		};
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}

\catcode`\;=13
% check the same, but with a different delimiter:
\pgfplotsset{
	colormap={actual}{
		of colormap={
		  viridis,
		  target pos={0,200,400,600,800,1000},
		  sample for=const,
		};
		of colormap={
		  hot,
		  target pos={1200,1400,1600},
		  sample for=const,
		};
	},
}

\pgfplotscolorbardrawstandalone[
  point meta min=0,point meta max=1600,
  colorbar horizontal,
  colorbar as legend,
  colorbar style={ticklabel style={font=\tiny}},
  colormap access=const
]

}

{
\pgfplotsset{
	colormap={actual}{
		samples of colormap={
		  5 of colormap/Set1-5,
		  target pos={0,200,400,600,800,1000},
		  sample for=const,
		},
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {200.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.005}%
	\def \pgfplots@loc@TMPa {{0.89412,0.10196,0.1098},{0.21606,0.4939,0.72122},{0.30185,0.68604,0.29066},{0.59558,0.30649,0.63863},{0.9991,0.49762,0.0014},{0.9991,0.49762,0.0014}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {5}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}


% this here should be the same:
\pgfplotsset{
	colormap={actual}{
		of colormap={
		  colormap/Set1-5,
		  target pos min=0,
		  target pos max=1000,
		  target pos={-1000,-100,0,200,400,600,800,1000,1100,1400},
		  sample for=const,
		},
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}

% this here should be the same:
\pgfplotsset{
	colormap={actual}{
		of colormap={
		  colormap/Set1-5,
		  target pos min*=0,
		  target pos max*=1000,
		  target pos={-1000,-100,0,200,400,600,800,1000,1100,1400},
		  sample for=const,
		},
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}

% this here should be the same:
\pgfplotsset{
	colormap={actual}{
		of colormap={
		  colormap/Set1-5,
		  target pos min*=0,
		  target pos max*=1000,
		  target pos={-1000,-100,200,400,600,800,1100,1400},
		  sample for=const,
		},
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}

% this here should be the same:
\pgfplotsset{
	colormap={actual}{
		samples of colormap={
		  5 of colormap/Set1-5,
		  target pos min*=0,
		  target pos max*=1000,
		  % give one target pos more than samples -- after applying
		  % min/max:
		  target pos={-1000,-100,0,200,400,600,800,1000,1100,1400},
		  sample for=const,
		},
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}

% this here should be the same:
\pgfplotsset{
	colormap={actual}{
		colors of colormap={
		  0,250,500,750,1000,1000 of colormap/Set1-5,
		  target pos={0,200,400,600,800,1000},
		},
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}
}

{
\pgfplotsset{
	colormap={actual}{
		of colormap={
		 	hot,
		   target pos={0,1000},
		   sample for=const,
		 }
	},
}
\pgfplotscolormapserializetomacro{actual}\simpleofcolormap
\def\expected{%
	\expandafter \def \csname pgfpl@cm@actual@h\endcsname {1000.0}%
	\expandafter \def \csname pgfpl@cm@actual@invh\endcsname {0.001}%
	\def \pgfplots@loc@TMPa {{0.0,0.0,1.0},{1.0,0.0,0.0}}%
	\pgfplotsarraynewempty {pgfpl@cm@actual}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual}%
		\fi
	}%
	\def \pgfpl@cm@actual@colspace {rgb}%
	\def \pgfpl@cm@actual@col@comps {3}%
	\def \pgfpl@cm@actual@lastindex {1}%
	\def \pgfplots@loc@TMPa {}%
	\pgfplotsarraynewempty {pgfpl@cm@actual@X}%
	\expandafter \pgfplotsutilforeachcommasep \pgfplots@loc@TMPa \as \pgfplots@loc@TMPb {%
		\ifx \pgfplots@loc@TMPb \pgfutil@empty \else
			\expandafter \pgfplotsarraypushback \pgfplots@loc@TMPb \to {pgfpl@cm@actual@X}%
		\fi
	}%
	\def \pgfpl@cm@actual@X@scale@order@z {0}%
}%
\pgfplotsassertequalstoknoexpand{\expected}{\simpleofcolormap}{}
}


\begingroup
	\pgfplotscreatecolormap{my map}{color=(green); color=(red); color=(blue); color=(yellow)}
	\pgfplotscolormapserializecomponentstomacro{my map}\actual

	% yellow is in CMYK; we see the result of the transformation to RGB.
	\pgfplotsassertequalstok{{0.0,1.0,0.0},{1.0,0.0,0.0},{0.0,0.0,1.0},{1,1,0}}{\actual}{}

	\pgfplotscolormapgetmeshwidth{my map}%
	\pgfplotsassertequalstok{333.35243}{\pgfplotsretval}{}

	\pgfplotscolormapgetcolorspace{my map}
	\pgfplotsassertequalstok{rgb}{\pgfplotsretval}{}

	\pgfplotscolormapifisuniform{my map}{}{\pgfplotsassertfail{should be uniform}}
\endgroup

\begingroup
	\pgfplotscreatecolormap{my map}{color(0cm)=(green); color(2cm)=(red); color=(blue); color=(yellow)}
	\pgfplotscolormapserializecomponentstomacro{my map}\actual

	\pgfplotsassertequalstok{{0.0,1.0,0.0},{1.0,0.0,0.0},{0.0,0.0,1.0},{1,1,0}}{\actual}{}

	\pgfplotscolormapgetmeshwidth{my map}%
	\pgfplotsassertequalstok{333.32396}{\pgfplotsretval}{}

	\pgfplotscolormapgetcolorspace{my map}
	\pgfplotsassertequalstok{rgb}{\pgfplotsretval}{}

	\pgfplotscolormapifisuniform{my map}{}{\pgfplotsassertfail{should be uniform}}
\endgroup

\message{^^J^^J}

\begingroup
	\pgfplotscreatecolormap{my map}{[1cm] color=(green); color=(red); color=(blue); color=(yellow)}
	\pgfplotscolormapserializecomponentstomacro{my map}\actual


	\pgfplotsassertequalstok{{0.0,1.0,0.0},{1.0,0.0,0.0},{0.0,0.0,1.0},{1,1,0}}{\actual}{}

	\pgfplotscolormapgetmeshwidth{my map}%
	\pgfplotsassertequalstok{333.35243}{\pgfplotsretval}{}

	\pgfplotscolormapgetcolorspace{my map}
	\pgfplotsassertequalstok{rgb}{\pgfplotsretval}{}

	\pgfplotscolormapifisuniform{my map}{}{\pgfplotsassertfail{should be uniform}}
\endgroup

\begingroup
	\pgfplotscreatecolormap{my map}{rgb=(0,1,0); rgb255=(0,255,0) cmyk=(0,0,0,1); cmyk255=(0,0,0,255) gray=(0)}
	\pgfplotscolormapserializecomponentstomacro{my map}\actual

	\pgfplotsassertequalstok{{0.0,1.0,0.0},{0.0,0.99998,0.0},{0,0,0},{0.00002,0.00002,0.00002},{0.0,0.0,0.0}}{\actual}{}

	\pgfplotscolormapgetmeshwidth{my map}%
	\pgfplotsassertequalstok{250.00005}{\pgfplotsretval}{}

	\pgfplotscolormapgetcolorspace{my map}
	\pgfplotsassertequalstok{rgb}{\pgfplotsretval}{}

	\pgfplotscolormapifisuniform{my map}{}{\pgfplotsassertfail{should be uniform}}
\endgroup

\begingroup
	\pgfplotscreatecolormap{my map}{color(0cm)=(white); color(1cm)=(orange!75!red)}
	\pgfplotscolormapserializecomponentstomacro{my map}\actual

	\pgfplotsassertequalstok{{1,1,1},{1.0,0.375,0.0}}{\actual}{}

	\csname pgfplots@colormap@showdebuginfofor\endcsname{my map}

	\pgfplotscolormapgetmeshwidth{my map}%
	\pgfplotsassertequalstok{1000.0}{\pgfplotsretval}{}

	\pgfplotscolormapgetcolorspace{my map}
	\pgfplotsassertequalstok{rgb}{\pgfplotsretval}{}

	\pgfplotscolormapifisuniform{my map}{}{\pgfplotsassertfail{should be uniform}}
\endgroup

\begingroup
	\pgfplotscreatecolormap{my map}{rgb255(0cm)=(0,0,128) rgb255(1cm)=(0,0,255) rgb255(3cm)=(0,255,255) rgb255(5cm)=(255,255,0) rgb255(7cm)=(255,0,0) rgb255(8cm)=(128,0,0)}
	\pgfplotscolormapserializecomponentstomacro{my map}\actual

	\pgfplotsassertequalstok{%
		{0.0,0.0,0.50195},% 0cm
		{0.0,0.0,0.99998},% 1cm
		{0.0,0.99998,0.99998},% 3cm
		{0.99998,0.99998,0.0},% 5cm
		{0.99998,0.0,0.0},% 7cm
		{0.50195,0.0,0.0}% 8cm
	}{\actual}{}

	\csname pgfplots@colormap@showdebuginfofor\endcsname{my map}

	\pgfplotscolormapgetmeshwidth{my map}%
	\pgfplotsassertequalstok{125.00143}{\pgfplotsretval}{}

	\pgfplotscolormapgetcolorspace{my map}
	\pgfplotsassertequalstok{rgb}{\pgfplotsretval}{}

	\pgfplotscolormapifisuniform{my map}{\pgfplotsassertfail{should NOT be uniform}}{}
\endgroup

\begingroup
	\pgfplotscreatecolormap{my map}{[1cm] rgb255(0cm)=(0,0,128) rgb255(1cm)=(0,0,255) rgb255(3cm)=(0,255,255) rgb255(5cm)=(255,255,0) rgb255(7cm)=(255,0,0) rgb255(8cm)=(128,0,0)}
	\pgfplotscolormapserializecomponentstomacro{my map}\actual

	\pgfplotsassertequalstok{%
		{0.0,0.0,0.50195},% 0cm
		{0.0,0.0,0.99998},% 1cm
		{0.0,0.49998,0.99997},% interpoalted 2cm
		{0.0,0.99998,0.99998},% 3cm
		{0.49998,0.99997,0.49998},% interpolated 4cm
		{0.99998,0.99998,0.0},% 5cm
		{0.99997,0.49998,0.0},% interpoalted 6cm
		{0.99998,0.0,0.0},% 7cm
		{0.50195,0.0,0.0}% 8cm
	}{\actual}{}

	\csname pgfplots@colormap@showdebuginfofor\endcsname{my map}

	\pgfplotscolormapgetmeshwidth{my map}%
	\pgfplotsassertequalstok{125.00143}{\pgfplotsretval}{}

	\pgfplotscolormapgetcolorspace{my map}
	\pgfplotsassertequalstok{rgb}{\pgfplotsretval}{}

	\pgfplotscolormapifisuniform{my map}{}{\pgfplotsassertfail{should be uniform}}
\endgroup

% NEW CHOICES since 1.8:
\begingroup
	\pgfkeys{/pgfplots/colormap default colorspace=rgb}
	\pgfplotscreatecolormap{my map}{HTML=(804040) hsb=(1,0.5,0.5) Hsb=(360,0.5,0.5) wave=(500)}
	\pgfplotscolormapserializecomponentstomacro{my map}\actual

	\pgfplotsassertequalstok{%
		{0.50195,0.25098,0.25098},%
		{0.5,0.25,0.25},%
		{0.5,0.25,0.25},%
		{0,1,0.49846}%
		}{\actual}{}

	\pgfplotscolormapgetmeshwidth{my map}%
	\pgfplotsassertequalstok{333.35243}{\pgfplotsretval}{}

	\pgfplotscolormapgetcolorspace{my map}
	\pgfplotsassertequalstok{rgb}{\pgfplotsretval}{}

	\pgfplotscolormapifisuniform{my map}{}{\pgfplotsassertfail{should be uniform}}
\endgroup

\begingroup
	\pgfkeys{/pgfplots/colormap default colorspace=rgb}
	\pgfplotscreatecolormap{my map}{HTML(0pt)=(804040) hsb=(1,0.5,0.5) Hsb(2cm)=(360,0.5,0.5) wave=(500)}
	\pgfplotscolormapserializecomponentstomacro{my map}\actual

	\pgfplotsassertequalstok{%
		{0.50195,0.25098,0.25098},%
		{0.5,0.25,0.25},%
		{0.5,0.25,0.25},%
		{0,1,0.49846}%
		}{\actual}{}

	\pgfplotscolormapgetmeshwidth{my map}%
	\pgfplotsassertequalstok{333.35243}{\pgfplotsretval}{}

	\pgfplotscolormapgetcolorspace{my map}
	\pgfplotsassertequalstok{rgb}{\pgfplotsretval}{}

	\pgfplotscolormapifisuniform{my map}{}{\pgfplotsassertfail{should be uniform}}
\endgroup
\end{document}
